﻿namespace DesignModeConsole.结构型.外观模式;

public class FacadeSample
{
    /// <summary>
    /// 门面模式屏蔽了客户端调用和子系统之间的复杂处理，也减少了和客户端之间的依赖
    /// </summary>
    public void Main()
    {
        var customer = new Customer("张三");

        var mortage = new Mortage();
        var eligible = mortage.isEligible(customer, 1000);

        var result = eligible ? "满足" : "不满足";
        Console.WriteLine($"顾客{customer.Name} {result}贷款要求");
    }
}

/// <summary>
/// 外观类
/// </summary>
public class Mortage
{
    /// <summary>
    /// 是否符合要求
    /// </summary>
    /// <param name="customer"></param>
    /// <param name="amount"></param>
    /// <returns></returns>
    public bool isEligible(Customer customer, int amount)
    {
        var bank = new Bank();
        var loan = new Loan();
        var credit = new Credit();

        var eligible = true;
        if (!bank.HasSufficientSavings(customer, amount))
        {
            eligible = false;
        }
        else if (!loan.HasNoBadLoans(customer))
        {
            eligible = false;
        }
        else if (!credit.HasGoodCredit(customer))
        {
            eligible = false;
        }
        return eligible;
    }
}